<%--
  Created by IntelliJ IDEA.
  User: dengdc
  Date: 2017/7/19
  Time: 17:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <title>联系人资料信息</title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript">
        //公司信息主键
        var agentRefId = '${agentRef.agentRefId}';

        var url = "/tGenComContact/list?arefId="+agentRefId;
        var formSetting = {
            grid: {
                id: "tGrid",
                title: "查询结果",
                url: url,
                colModel: [{
                    index: "COM_CONTACT_ID",
                    name: "comContactId",
                    label: '主键',
                    key: true,
                    hidden:true
                },
                {label: '姓名', name: 'name', index: 'name'},
                {label: '部门', name: 'dept', index: 'dept'},
                {label: '职务', name: 'position', index: 'position'},
                {label: '联系电话', name: 'telPhone', index: 'TEL_PHONE'},
                {label: '邮箱', name: 'email', index: 'email'},
                {label: 'QQ', name: 'qq', index: 'QQ'}],
                multiselect: true
            }
        };
        $(document).ready(function () {
            $("#table").mrdForm(formSetting);
            doResize();
            $(window).resize(function () {
                doResize();
            });

            $(".ui-jqgrid-title").text("联系人信息列表");
        });

        function doResize() {
            var ss = getPageSize();
            $("#tGrid").jqGrid('setGridHeight', ss.WinH - 280);
        }

        function getPageSize() {
            var winW, winH;
            if (window.innerHeight) {// all except IE
                winW = window.innerWidth;
                winH = window.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
                winW = document.documentElement.clientWidth;
                winH = document.documentElement.clientHeight;
            } else if (document.body) { // other
                winW = document.body.clientWidth;
                winH = document.body.clientHeight;
            }
            return {WinW: winW, WinH: winH};
        }

        //选择多条记录
        function getSels(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                layer.alert("请选择一条记录");
                return;
            }

            return grid.getGridParam("selarrrow");
        }

        //选择一条记录
        function getSelectedRowById(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                layer.alert("请选择一条记录");
                return;
            }

            var selectedIDs = grid.getGridParam("selarrrow");
            if (selectedIDs.length > 1) {
                layer.alert("只能选择一条记录");
                return;
            }

            return selectedIDs[0];
        }

        /**
         * 弹出窗口初始化
         * @author han
         **/
        function clearForm() {
            $('#comContactId').val("");
            $('#name').val("");
            $('#telPhone').val("");
            $('#email').val("");
            $('#dept').val("");
            $('#position').val("");
            $('#qq').val("");
        }

        /**
         * 新增
         * @author han
         */
        function add(){
            clearForm();
            layer.open({
                type: 1,
                area: ['600px', '400px'],
                title: '新增联系人',
                maxmin: true, //开启最大化最小化按钮
                content: $("#winContent"),
                btn: ['确定', '关闭'],
                yes: function (index, layero) {
                    if(!isNullInput()){
                        return;
                    }

                    var param = {};
                    param.comContactId = $('#comContactId').val();
                    param.name = $('#name').val();
                    param.telPhone = $('#telPhone').val();
                    param.email = $('#email').val();
                    param.dept = $('#dept').val();
                    param.position = $('#position').val();
                    param.qq = $('#qq').val();
                    param.arefId =  agentRefId;
                    var url = "/tGenComContact/save";

                    $.ajax({
                        type: "POST",
                        url: url,
                        data: param,
                        success: function (r) {
                            if (r.error_code == 0) {
                                $("#tGrid").trigger("reloadGrid");
                            } else {
                                layer.alert(r.msg);
                            }
                            layer.closeAll();
                        }
                    });
                },
                cancel: function (index) {
                    clearForm();
                }
        });
        }

        /**
         * 判空
         * @author han
         * */
        function isNullInput(){
            var nameVal=$("#name").val();
            var telPhoneVal=$("#telPhone").val();
            var result = true;
            if(nameVal==null||nameVal==undefined||jQuery.trim(nameVal) ==""){
                result = false;
                layer.alert("姓名不能为空");
            }
            if(telPhoneVal==null||telPhoneVal==undefined||jQuery.trim(telPhoneVal) ==""){
                result = false;
                layer.alert("电话号码不能为空");
            }
            return result;
        }

        /**
         * 修改
         * @author han
         */
        function modify(){
            var id = getSelectedRowById('tGrid');
            if (id == null) {
                return;
            }
            var row = $("#tGrid").getRowData(id);

            $('#comContactId').val(row.comContactId);
            $('#name').val(row.name);
            $('#telPhone').val(row.telPhone);
            $('#email').val(row.email);
            $('#dept').val(row.dept);
            $('#position').val(row.position);
            $('#qq').val(row.qq);

            layer.open({
                type: 1,
                area: ['600px', '400px'],
                title: '修改联系人',
                maxmin: true, //开启最大化最小化按钮
                content: $("#winContent"),
                btn: ['确定', '关闭'],
                yes: function (index, layero) {
                    if(!isNullInput()){
                        return;
                    }

                    var param = {};
                    param.comContactId = $('#comContactId').val();
                    param.name = $('#name').val();
                    param.telPhone = $('#telPhone').val();
                    param.email = $('#email').val();
                    param.dept = $('#dept').val();
                    param.position = $('#position').val();
                    param.qq = $('#qq').val();
                    param.arefId =  agentRefId;
                    var url = "/tGenComContact/update";

                    $.ajax({
                        type: "POST",
                        url: url,
                        data: param,
                        success: function (r) {
                            if (r.error_code == 0) {
                                $("#tGrid").trigger("reloadGrid");
                            } else {
                                layer.alert(r.msg);
                            }
                            layer.closeAll();
                        }
                    });
                },
                cancel: function (index) {
                    clearForm();
                }
            });
        }

        /**
         * 删除
         * @author han
         */
        function del(){
            var ids = getSels("tGrid");
            if (ids == null) {
                return;
            }

            $.ajax({
                type: "POST",
                url: "/tGenComContact/delete",
                contentType: "application/json",
                data: JSON.stringify(ids),
                success: function (r) {
                    if (r.error_code == 0) {
                        layer.alert("删除成功");
                        $("#tGrid").trigger("reloadGrid");
                    } else {
                        layer.alert(r.msg);
                    }
                }
            });
        }
    </script>
    <style type="text/css">
        .ld_duiqi{
            text-align:center;
            text-align:justify;
            text-justify:distribute-all-lines;
            text-align-last:justify;
        }
    </style>
</head>
<body>
<div style="height: 170px">
<fieldset id="mf_container0" class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
    <div class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header"><a
            href="javascript:void(0)" class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button"><span
            class="ui-icon ui-icon-circle-triangle-s"></span> </a><span class="replace-ui-jqgrid-title">联系人信息</span>
    </div>
        <table class="mrdTable" style="width: 100%;">
            <tbody>
            <tr>
                <td>
                    <table width="100%" border="0" cellspacing="3" cellpadding="0">
                        <tr>
                            <td width="20px"></td>
                            <td width="150px" class="ld_duiqi">公司名称：</td>
                            <td>${agentRef.recessiveCompanyInfo.name}</td>
                        </tr>
                        <tr>
                            <td width="20px"></td>
                            <td class="ld_duiqi">同一社会信用代码：</td>
                            <td>${agentRef.recessiveCompanyInfo.uniteCode}</td>
                        </tr>
                        <tr>
                            <td width="20px"></td>
                            <td class="ld_duiqi">海关企业注册代码：</td>
                            <td>${agentRef.recessiveCompanyInfo.customsCode}</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr class="mrdBtnTr">
                <td id="mf_buttons_container" colspan="6" align="right">
                    <input type="button" id="queryButton"  onclick="add();" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false" value="新增" style="margin: 3px; font-size: 12px;">
                    <input type="button" id="reset" onclick="modify();" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false" value="修改" style="margin: 3px; font-size: 12px;">
                    <input type="button" id="updatebtn0" onclick="del();" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false" value="刪除" style="margin: 3px; font-size: 12px;">
                    <%--<input type="button" id="bakbtn0" onclick="javascript:history.back();" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false" value="返回" style="margin: 3px; font-size: 12px;">--%>
                </td>
            </tr>
            </tbody>
        </table>
</fieldset>
</div>
<div id="table"></div>
<div id="winContent" style="display:none;margin:5px 5px 5px 5px;">
    <table width="100%" border="1" cellpadding="1" bordercolor="#eeeeee">
        <tr bgcolor="#FFFFFF">
            <td width="198" height="38" align="right" bgcolor="#f8f8f8">姓名：</td>
            <td width="345" align="left">
                <input type="hidden" id="comContactId" name="comContactId">
                <input id="name" name="name" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td width="198" height="38" align="right" bgcolor="#f8f8f8">部门：</td>
            <td width="345" align="left">
                <input id="dept" name="dept" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td width="198" height="38" align="right" bgcolor="#f8f8f8">职务：</td>
            <td width="345" align="left">
                <input id="position" name="position" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td width="198" height="38" align="right" bgcolor="#f8f8f8">联系电话：</td>
            <td width="345" align="left">
                <input id="telPhone" name="telPhone" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td align="right" height="38" bgcolor="#f8f8f8">邮箱：</td>
            <td align="left">
                <input id="email" name="email" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td align="right" height="38" bgcolor="#f8f8f8">QQ：</td>
            <td align="left">
                <input id="qq" name="qq" size="45"/>
            </td>
        </tr>
    </table>
</div>
</body>
</html>
